package cn.com.dcsgo.validation;

import cn.com.dcsgo.validation.validator.ElementsOfValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 自定义参数校验注解
 * 校验字段的元素值必须在指定的元素值列表中（校验字段为null或空集合视为校验通过，如不允许为null或空集合请额外使用@NotNull或@NotEmpty修饰字段）
 *
 * @author Dcsgo
 * @since 2025/9/28 13:09
 */
@Constraint(validatedBy = ElementsOfValidator.class)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
public @interface ElementsOf {
    String[] value() default {};

    String message() default "${validatedValue}的元素值必须在{value}中";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
}
